<template>
  <el-dialog :title="title" :visible.sync="openPublish" width="500px" append-to-body>
    <el-form ref="formPublish" :model="formPublish" label-width="80px">
      <el-form-item label="商品货号" prop="sku">
        <el-input v-model="formPublish.sku" placeholder="请输入商品货号" disabled/>
      </el-form-item>
      <el-form-item label="商品标题" prop="title">
        <el-input v-model="formPublish.title" placeholder="请输入商品标题" type="textarea" disabled/>
      </el-form-item>
      <el-form-item label="上架状态" prop="publishStatus">
        <el-select v-model="formPublish.publishStatus" placeholder="请选择上架状态" clearable @change="$forceUpdate()">
          <el-option
            v-for="dict in dict.type.publish_status"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitFormPublish">确 定</el-button>
      <el-button @click="cancelPublish">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { publishProduct } from "@/api/supermarket/product";

export default {
  name: "PublishProductForm",
  dicts: ['publish_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "",
      // 是否显示上下架弹出层
      openPublish: false,
      // 表单参数
      formPublish: {},
    };
  },
  methods: {
    /** 上下架按钮操作 */
    handlePublish(row) {
      this.resetPublish();
      if(row.product.auditStatus != 2){
        this.$modal.msgWarning("审核通过后，才能执行此操作！！！");
        return 0;
      }
      this.formPublish.sku = row.product.sku;
      this.formPublish.title = row.product.title;
      this.formPublish.publishStatus = row.product.publishStatus;
      this.title = "上下架商品信息";
      this.openPublish = true;
    },
    /** 提交上下架按钮 */
    submitFormPublish() {
      this.loading = true;
      publishProduct(this.formPublish).then(response => {
        this.$parent.getList();
        this.resetPublish();
        this.loading = false;
        this.openPublish = false;
      });
    },
    // 取消按钮
    cancelPublish() {
      this.openPublish = false;
      this.resetPublish();
    },
    // 重置审核表单
    resetPublish() {
      this.formAudit = {
        sku: null,
        title: null,
        publishStatus: null
      };
      this.resetForm("formPublish");
    },
  }
}
</script>